<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
<%@ page   import="java.sql.*"%>   
<%@ page   import="javax.sql.*"%>   
<%@ page   import="javax.naming.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'testConnect.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    This is my JSP page. <br>
<%out.println("<h1>Hello，test JNDI ! </h1>");%> 
  <%     Context ctx = new InitialContext();    
           Context envctx = (Context) ctx.lookup("java:comp/env");    
           DataSource ds = (DataSource) envctx.lookup("jdbc/TestDB");    
          Connection conn=ds.getConnection();    
          Statement st=conn.createStatement();      
        String   sql="select   *   from   jobs";    
       ResultSet   rs=st.executeQuery(sql);    
     while(rs.next())   {%>    
    您的第一个字段内容为：<%=rs.getString(1)%>    
     您的第二个字段内容为：<%=rs.getString(2)%>    
     <br> 
     <%}%>    
  <%out.print("使用jdbc驱动操作数据库操作成功，恭喜你");%>    
  <%rs.close();    
  st.close();    
  conn.close();    
  %>   

  </body>
</html>
